package com.wufun.overseas.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wufun.overseas.R;

import java.util.List;

/**
 * Created by tangbl on 2017/11/21.
 */

public class DataAdapter extends BaseAdapter {

    private List<String> mList;
    private Context context;

    public DataAdapter(Context context, List<String> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_data_view, null);
            //初始化
            viewHolder.content_tv = (TextView) convertView.findViewById(R.id.content_tv);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.content_tv.setText(mList.get(position));

        return convertView;
    }

    class ViewHolder {
        public TextView content_tv;
    }
}
